goog.provide('gjslint.ErrorEntry');

goog.require('goog.dom');
goog.require('goog.dom.classes');
goog.require('goog.ui.Component');

gjslint.ErrorEntry = function(errorJson) {
  goog.base(this);		       
  this.errorJson_ = errorJson;
};
goog.inherits(gjslint.ErrorEntry, goog.ui.Component);

gjslint.ErrorEntry.prototype.createDom = function() {
  goog.base(this, 'createDom');
  
  var base = goog.getCssName('gjslint-error-entry');
  var elem = this.getElement();
  
  goog.dom.classes.add(elem, base);
  
  var json = this.errorJson_;
  var tokenJson = json['token'];
  
  var message = goog.string.subs('Line %s: %s', tokenJson['line_number'],
      json['message']);
  
  var messageDiv = goog.dom.createDom('div', goog.getCssName(base, 'message'), message);

  goog.dom.appendChild(elem, messageDiv);
  
  var codeDiv = goog.dom.createDom('div', goog.getCssName(base, 'code'), tokenJson['line']);
  goog.dom.appendChild(elem, codeDiv);

  var spaces = Math.max(0, json['start_index']);
  var charString = goog.string.repeat(' ', spaces) + '^';
  var charDiv = goog.dom.createDom('div', goog.getCssName(base, 'code'), charString);
  goog.dom.appendChild(elem, charDiv);
  
  goog.dom.appendChild(elem, goog.dom.createDom('div', goog.getCssName(base, 'code'),
      goog.string.subs('Column: %s', json['start_index'])));
};